//
// Created by youle on 20-1-17.
//

#ifndef JFXSSL_JFLOG_H
#define JFXSSL_JFLOG_H

//#include <googleglog/logging.h>
#include <glog/logging.h>
#include <string.h>
#include <stdarg.h>


#define LOG_BUFF_LEN 1024
#define JFINFO  INFO
#define JFWARN  WARNING
#define JFERROR ERROR
#define JFFATAL FATAL

#define JFLOG_V5 5
#define JFLOG_V6 6
#define JFLOG_V7 7
#define JFLOG_V8 8

void JFLogInit( bool glogInit = false );

#define JFLOG(level, format, ...) \
{                                 \
    char logBuff[LOG_BUFF_LEN] = {0}; \
    snprintf(logBuff, LOG_BUFF_LEN, format, ##__VA_ARGS__); \
    LOG(level) << "[EdgeServer] " << __FUNCTION__ << " " << logBuff;    \
}

#define JFLOG_IF(level, condition, format, ...) \
{                                 \
    if(condition){   \
        char logBuff[LOG_BUFF_LEN] = {0}; \
        snprintf(logBuff, LOG_BUFF_LEN, format, ##__VA_ARGS__); \
        LOG(level) << "[EventServer] " << __FUNCTION__ << logBuff;    \
    }  \
}


#define JFLOG_EVERY_N(level, n, format, ...) \
{                                         \
   static int LOG_OCCURRENCES = 0;       \
   if((++LOG_OCCURRENCES)%(n) == 1) {    \
      char logBuff[LOG_BUFF_LEN] = {0}; \
      snprintf(logBuff, LOG_BUFF_LEN, format, ##__VA_ARGS__); \
      LOG(level) << "[EventServer] " << __FUNCTION__ << " EVERY " << n << " " << logBuff;    \
   }                                     \
}

#define JFVLOG(level, format, ...) \
{                                 \
    char logBuff[LOG_BUFF_LEN] = {0}; \
    snprintf(logBuff, LOG_BUFF_LEN, format, ##__VA_ARGS__); \
    VLOG(level) << "[EventServer] " << __FUNCTION__ << logBuff;    \
}

#define JFVLOG_IF(level, condition, format, ...) \
{                                 \
    if(condition){   \
        char logBuff[LOG_BUFF_LEN] = {0}; \
        snprintf(logBuff, LOG_BUFF_LEN, format, ##__VA_ARGS__); \
        VLOG(level) << "[EventServer] " << __FUNCTION__ << logBuff;    \
    }  \
}

#endif //JFXSSL_JFLOG_H
